package com.mengshuai.technology.order.rocketmq;

import com.mengshuai.technology.order.rocketmq.producer.RocketMQProducerService;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * rocketmq 测试入口
 *
 * @author 孟帅
 * @since 2025/6/27
 */
@RestController
@RequestMapping("/rocketmqController")
public class RocketmqController {
    @Autowired
    private RocketMQProducerService producerService;

    /**
     * 同步发送
     *
     * @param topic 主题
     * @param tag 标签
     * @param key 键
     * @param message 消息
     */
    @GetMapping("/sendSyncMessage")
    public SendResult sendSyncMessage(@RequestParam String topic, @RequestParam String tag, @RequestParam String key,
                            @RequestParam String message) {
        // 同步发送
        return producerService.sendSyncMessage(topic, tag, key, message);
    }

    /**
     * 异步发送
     *
     * @param topic 主题
     * @param tag 标签
     * @param key 键
     * @param message 消息
     */
    @GetMapping("/sendAsyncMessage")
    public void sendAsyncMessage(@RequestParam String topic, @RequestParam String tag, @RequestParam String key,
                                      @RequestParam String message) {
        // 异步发送
         producerService.sendAsyncMessage(topic, tag, key, message);
    }

    /**
     * 事务发送
     *
     * @param topic 主题
     * @param tag 标签
     * @param key 键
     * @param message 消息
     */
    @GetMapping("/sendTransactionMessage")
    public void sendTransactionMessage(@RequestParam String topic, @RequestParam String tag, @RequestParam String key,
                                 @RequestParam String message) {
        // 事务发送
        producerService.sendTransactionMessage(topic, tag, key, message);
    }
}
